package io.serialize;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

@SuppressWarnings("serial")
class Employee1 implements Serializable {
	private int id;
	private String name;

	public Employee1() {
	}

	public Employee1(int i, String s) {
		this.id = i;
		this.name = s;
	}

	public String toString() {
		return "ID: " + this.id + "\nName: " + this.name;
	}
}

public class IOSerializable {
	public static void main(String args[]) throws IOException,
			ClassNotFoundException {

		// SERIALIZATION
		Employee1 e = new Employee1(10, "Super");
		FileOutputStream fos = new FileOutputStream("object.dat");
		ObjectOutputStream oos = new ObjectOutputStream(fos);
		oos.writeObject(e);
		System.out.println("object Serialization..");

		// DESERIALIZATION
		FileInputStream fis = new FileInputStream("object.dat");
		ObjectInputStream ois = new ObjectInputStream(fis);
		Object obj = ois.readObject();
		Employee1 ee = (Employee1) obj;
		System.out.println(ee);
	}
}